package com.ct.gd.passport.domain;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.ct.gd.passport.common.connect.CtServer;
import com.ct.gd.passport.common.constants.Config;
import com.ct.gd.passport.common.constants.Protocol;
import com.fuckhtc.gson.Gson;
import com.fuckhtc.gson.annotations.SerializedName;
import com.fuckhtc.gson.reflect.TypeToken;
import com.up91.common.android.exception.NullDataException;

public class TravelPortInfo {

	@SerializedName("portName")
	private String 	portName;

	@SerializedName("through")
	private String		through;
	
	@SerializedName("wait")
	private String wait;

	
	public TravelPortInfo() {
		super();
	}


	public TravelPortInfo(String portName, String through, String wait) {
		super();
		this.portName = portName;
		this.through = through;
		this.wait = wait;
	}


	public String getPortName() {
		return portName;
	}


	public void setPortName(String portName) {
		this.portName = portName;
	}



	public String getThrough() {
		return through;
	}


	public void setThrough(String through) {
		this.through = through;
	}


	public String getWait() {
		return wait;
	}


	public void setWait(String wait) {
		this.wait = wait;
	}


	public static List<TravelPortInfo> load() {
		List<TravelPortInfo> infos = new ArrayList<TravelPortInfo>();
		TravelPortInfo info = new TravelPortInfo();
		info.setPortName("口岸");
		info.setThrough("今日通行");
		info.setWait("等待通关");
		infos.add(info);
		
		if (Config.ON_LINE) {
			String json = CtServer.getServer().doGet(Protocol.Commands.REST_IMMIGRATION_QUERY, null);
			try {
				JSONObject jObj = new JSONObject(json);
				TypeToken<List<TravelPortInfo>> typeToken = new TypeToken<List<TravelPortInfo>>() {
				};
				List<TravelPortInfo> infos2 = new Gson().fromJson(jObj.getString(Protocol.Fields.DATA), typeToken.getType());
				for(TravelPortInfo t : infos2){
					infos.add(t);
				}
			} catch (JSONException e) {
				e.printStackTrace();
				throw new NullDataException();
			}
		}
		return infos;
	}

}
